﻿@inject IStringLocalizerAsync<ClientTokens> Localizer
@inject IOptions<Settings> Options
@if (Model.ProtocolType == "oidc")
{
    <div class="mb-3 row">
        <label class="col col-form-label">
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizeCheckbox Name="show-all" Label="@Localizer["show all options"]" @bind-Value="@_showAllOptions" />
        </div>
    </div>
    <div class="mb-3 row">
        <label class="col col-form-label pt-0" for="access-token-type">
            @Localizer["allowed identity token signing algorithms"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <ClientAllowedIdentityTokenSigningAlgorithms Model="Model" />
        </div>
    </div>
    <div class="mb-3 row">
        <label class="col col-form-label pt-0" for="access-token-type">
            @Localizer["access token type"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizeView Policy="@SharedConstants.WRITERPOLICY">
                <Authorized Context="accessTokenType">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="access-token-type"
                           value="0"
                           checked="@(Model.AccessTokenType == (int)Models.AccessTokenType.Jwt)"
                           @onchange="@(() => SetTokenType(Models.AccessTokenType.Jwt))" />
                        <label class="form-check-label" for="jwt" @onclick="@(() => SetTokenType(Models.AccessTokenType.Jwt))">JWT</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="access-token-type"
                           value="1"
                           checked="@(Model.AccessTokenType == (int)Models.AccessTokenType.Reference)"
                           @onchange="@(() => SetTokenType(Models.AccessTokenType.Reference))" />
                        <label class="form-check-label" for="reference" @onclick="@(() => SetTokenType(Models.AccessTokenType.Reference))">Reference</label>
                    </div>
                </Authorized>
                <NotAuthorized Context="accessTokenType">
                    @(((Models.AccessTokenType)Model.AccessTokenType).ToString())
                </NotAuthorized>
            </AuthorizeView>
        </div>
    </div>
    if (_showAllOptions || Model.IsWebClient())
    {
        <div class="mb-3 row">
            <label class="col col-form-label" for="access-token">
                @Localizer["authorization code lifetime"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizedToken Name="authorization-code-lifetime" QuickValues="_idTokenQuickValues" @bind-Value="@Model.AuthorizationCodeLifetime" TokenValueChanged="TokenChanded" />
                <div>
                    <AuthorizeCheckbox Name="require-pkce" Label="@Localizer["require PKCE"]" @bind-Value="@Model.RequirePkce" />
                </div>
                <div>
                    <AuthorizeCheckbox Name="allow-plain-text-pkce" Label="@Localizer["allow plain text PKCE"]" @bind-Value="@Model.AllowPlainTextPkce" />
                </div>
            </div>
        </div>
    }
    <div class="mb-3 row">
        <label class="col col-form-label" for="access-token">
            @Localizer["access token lifetime"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizedToken Name="access-token" QuickValues="_accessTokenQuickValues" @bind-Value="@Model.AccessTokenLifetime" TokenValueChanged="TokenChanded" />
            <div>
                <AuthorizeCheckbox Name="include-jwt-id" Label="@Localizer["include JWT id"]" @bind-Value="@Model.IncludeJwtId" />
            </div>
            @if (_showAllOptions || Model.IsSpaClient())
            {
                <div>
                    <AuthorizeCheckbox Name="allow-access-token-via-browser" Label="@Localizer["allow access tokens via browser"]" @bind-Value="@Model.AllowAccessTokensViaBrowser" />
                </div>
            }
        </div>
    </div>
    <div class="mb-3 row">
        <label class="col col-form-label" for="id-token">
            @Localizer["id token lifetime"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizedToken Name="id-token" QuickValues="_idTokenQuickValues" @bind-Value="@Model.IdentityTokenLifetime" TokenValueChanged="TokenChanded" />
            <div>
                <AuthorizeCheckbox Name="include-claims" Label="@Localizer["always include user claims in id token"]" @bind-Value="@Model.AlwaysIncludeUserClaimsInIdToken" />
            </div>
        </div>
    </div>
    <div class="mb-3 row">
        <label class="col col-form-label" for="salt">
            @Localizer["pairwise subject salt"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizeText Id="salt" @bind-Value="@Model.PairWiseSubjectSalt" MaxLength="200" />
        </div>
    </div>
    @if (_showAllOptions || Model.CanUseRefreshToken())
    {
        <div class="mb-3 row">
            <label class="col col-form-label pt-0" for="refesh-token-usage">
                @Localizer["refresh token usage"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizeView Policy="@SharedConstants.WRITERPOLICY">
                    <Authorized Context="refreshTokenUsage">
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="refresh-token-usage"
                           value="0"
                           checked="@(Model.RefreshTokenUsage == (int)Models.RefreshTokenUsage.ReUse)"
                           @onchange="@(() => SetRefreshTokenUsage(Models.RefreshTokenUsage.ReUse))" />
                            <label class="form-check-label" for="jwt" @onclick="@(() => SetRefreshTokenUsage(Models.RefreshTokenUsage.ReUse))">@Localizer["Re use"]</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="refresh-token-usage"
                           value="1"
                           checked="@(Model.RefreshTokenUsage == (int)Models.RefreshTokenUsage.OneTimeOnly)"
                           @onchange="@(() => SetRefreshTokenUsage(Models.RefreshTokenUsage.OneTimeOnly))" />
                            <label class="form-check-label" for="reference" @onclick="@(() => SetRefreshTokenUsage(Models.RefreshTokenUsage.OneTimeOnly))">@Localizer["One time only"]</label>
                        </div>
                    </Authorized>
                    <NotAuthorized Context="refreshTokenUsage">
                        @(((Models.RefreshTokenUsage)Model.RefreshTokenUsage).ToString())
                    </NotAuthorized>
                </AuthorizeView>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="col col-form-label pt-0" for="refesh-token-expiration">
                @Localizer["refresh token expiration"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizeView Policy="@SharedConstants.WRITERPOLICY">
                    <Authorized Context="refreshTokenExpiration">
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="refresh-token-expiration"
                           value="0"
                           checked="@(Model.RefreshTokenExpiration == (int)Models.RefreshTokenExpiration.Sliding)"
                           @onchange="@(() => SetRefreshTokenExpiration(Models.RefreshTokenExpiration.Sliding))" />
                            <label class="form-check-label" for="jwt" @onclick="@(() => SetRefreshTokenExpiration(Models.RefreshTokenExpiration.Sliding))">@Localizer["Sliding"]</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="refresh-token-expiration"
                           value="1"
                           checked="@(Model.RefreshTokenExpiration == (int)Models.RefreshTokenExpiration.Absolute)"
                           @onchange="@(() => SetRefreshTokenExpiration(Models.RefreshTokenExpiration.Absolute))" />
                            <label class="form-check-label" for="reference" @onclick="@(() => SetRefreshTokenExpiration(Models.RefreshTokenExpiration.Absolute))">@Localizer["Absolute"]</label>
                        </div>
                    </Authorized>
                    <NotAuthorized Context="refreshTokenUsage">
                        @(((Models.RefreshTokenUsage)Model.RefreshTokenUsage).ToString())
                    </NotAuthorized>
                </AuthorizeView>
            </div>
        </div>
        @if (Model.RefreshTokenExpiration == (int)Models.RefreshTokenExpiration.Absolute)
        {
            <div class="mb-3 row">
                <label class="col col-form-label" for="refresh-token">
                    @Localizer["absolute refresh token lifetime"]
                </label>
                <div class="col-lg-8 col-sm-12">
                    <AuthorizedToken Name="refresh-token" QuickValues="_absoluteRefreshTokenQuickValues" @bind-Value="@Model.AbsoluteRefreshTokenLifetime" TokenValueChanged="TokenChanded" />
                    <div>
                        <AuthorizeCheckbox Name="update-access-token" Label="@Localizer["update access token on refresh"]" @bind-Value="@Model.UpdateAccessTokenClaimsOnRefresh" />
                    </div>
                </div>
            </div>
        }
        else
        {
            <div class="mb-3 row">
                <label class="col col-form-label" for="refresh-token">
                    @Localizer["sliding refresh token lifetime"]
                </label>
                <div class="col-lg-8 col-sm-12">
                    <AuthorizedToken Name="refresh-token" QuickValues="_slidingRefreshTokenQuickValues" @bind-Value="@Model.SlidingRefreshTokenLifetime" TokenValueChanged="TokenChanded" />
                    <div>
                        <AuthorizeCheckbox Name="update-access-token" Label="@Localizer["update access token on refresh"]" @bind-Value="@Model.UpdateAccessTokenClaimsOnRefresh" />
                    </div>
                </div>
            </div>
        }
    }
    @if (_showAllOptions || Model.IsCiba())
    {
        <div class="mb-3 row">
            <label class="col col-form-label" for="ciba-lifetime">
                @Localizer["ciba lifetime"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizedToken Name="ciba-lifetime" QuickValues="_cibaLifetimeQuickValues" @bind-Value="@Model.CibaLifetime" TokenValueChanged="TokenChanded" />
            </div>
        </div>
        <div class="mb-3 row">
            <label class="col col-form-label" for="polling-interval">
                @Localizer["polling interval"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizedToken Name="polling-interval" QuickValues="_pollingIntervalQuickValues" @bind-Value="@Model.PollingInterval" TokenValueChanged="TokenChanded" />
            </div>
        </div>
    }
    <div class="mb-3 row">
        <label class="col col-form-label" for="sso-lifetime">
            @Localizer["sso lifetime"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizedToken Name="sso-lifetime" QuickValues="_ssoLifetimeQuickValues" @bind-Value="@Model.UserSsoLifetime" TokenValueChanged="TokenChanded" />
        </div>
    </div>
    @if (Options.Value.ServerSideSessionEnabled)
    {
        <div class="mb-3 row">
            <label class="col col-form-label" for="coordinate-lifetime-with-user-session">
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizeNullableCheckbox Name="coordinate-lifetime-with-user-session" @bind-Value="@Model.CoordinateLifetimeWithUserSession" Label="@Localizer["coordinate lifetime with user session"]" />
            </div>
        </div>
    }
    @if (_showAllOptions || Model.IsDevice())
    {
        <div class="mb-3 row">
            <label class="col col-form-label" for="device-flow-lifetime">
                @Localizer["device flow request lifetime"]
            </label>
            <div class="col-lg-8 col-sm-12">
                <AuthorizedToken Name="device-flow-lifetime" QuickValues="_deviceCodeLifetimeQuickValues" @bind-Value="@Model.DeviceCodeLifetime" TokenValueChanged="TokenChanded" />
            </div>
        </div>
    }
}
else
{
    <div class="mb-3 row">
        <label class="col col-form-label" for="id-token">
            @Localizer["lifetime"]
        </label>
        <div class="col-lg-8 col-sm-12">
            <AuthorizedToken Name="id-token" QuickValues="_accessTokenQuickValues" @bind-Value="@Model.IdentityTokenLifetime" TokenValueChanged="TokenChanded" />
        </div>
    </div>
}